{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "thousand-market",
   "metadata": {},
   "source": [
    "# Scheduler K8S Test\n",
    "\n",
    "Assumes you have a Kind cluster running with metallb. No other dependencies required.\n",
    "You can use [Seldon Ansible Kind Playbook](https://github.com/SeldonIO/ansible-k8s-collection/blob/master/playbooks/kind.yaml)\n",
    "\n",
    "## Setup\n",
    "\n",
    "* `make kind-image-install-all`\n",
    "* `make deploy` \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "representative-intersection",
   "metadata": {},
   "outputs": [],
   "source": [
    "SCHEDULER_IP=!kubectl get svc seldon-scheduler -n seldon-mesh -o jsonpath='{.status.loadBalancer.ingress[0].ip}'\n",
    "SCHEDULER_IP=SCHEDULER_IP[0]\n",
    "import os\n",
    "os.environ['SCHEDULER_IP'] = SCHEDULER_IP"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "delayed-resort",
   "metadata": {},
   "outputs": [],
   "source": [
    "MESH_IP=!kubectl get svc seldon-mesh -n seldon-mesh -o jsonpath='{.status.loadBalancer.ingress[0].ip}'\n",
    "MESH_IP=MESH_IP[0]\n",
    "import os\n",
    "os.environ['MESH_IP'] = MESH_IP"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "described-girlfriend",
   "metadata": {},
   "source": [
    "## No Auth Example"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "asian-roller",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{ \\\n",
    "              \"meta\":{\"name\":\"iris\"},\\\n",
    "              \"modelSpec\":{\"uri\":\"gs://seldon-models/mlserver/iris\",\\\n",
    "                           \"requirements\":[\"sklearn\"],\\\n",
    "                           \"memoryBytes\":500},\\\n",
    "              \"deploymentSpec\":{\"replicas\":1}}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/LoadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "suitable-chamber",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/ModelStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "latest-raleigh",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "!curl -v http://${MESH_IP}/v2/models/iris/infer -H \"Content-Type: application/json\" -H \"seldon-model: iris\"\\\n",
    "        -d '{\"inputs\": [{\"name\": \"predict\", \"shape\": [1, 4], \"datatype\": \"FP32\", \"data\": [[1, 2, 3, 4]]}]}'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "northern-martial",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model_name\":\"iris\",\"inputs\":[{\"name\":\"input\",\"contents\":{\"fp32_contents\":[1,2,3,4]},\"datatype\":\"FP32\",\"shape\":[1,4]}]}' \\\n",
    "        -plaintext \\\n",
    "        -import-path ../../apis \\\n",
    "        -proto ../../apis/mlops/v2_dataplane/v2_dataplane.proto \\\n",
    "        -rpc-header seldon-model:iris \\\n",
    "       ${MESH_IP}:80 inference.GRPCInferenceService/ModelInfer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "coordinated-enzyme",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/UnloadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "legal-quarter",
   "metadata": {},
   "outputs": [],
   "source": [
    "!curl -v http://${MESH_IP}/v2/models/iris/infer -H \"Content-Type: application/json\" -H \"seldon-model: iris\"\\\n",
    "        -d '{\"inputs\": [{\"name\": \"predict\", \"shape\": [1, 4], \"datatype\": \"FP32\", \"data\": [[1, 2, 3, 4]]}]}'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "starting-blond",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/ModelStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "boring-threshold",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"name\":\"mlserver\"}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/ServerStatus"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "corresponding-headquarters",
   "metadata": {},
   "source": [
    "## Auth Preparation - Prepare Minio with Iris Model\n",
    "\n",
    "Install minio in a kind cluster with Ansible.\n",
    "\n",
    "Create rclone.conf changing the ip address for minio as appropriate\n",
    "\n",
    "```\n",
    "[s3]\n",
    "type = s3\n",
    "provider = minio\n",
    "env_auth = false\n",
    "access_key_id = minioadmin\n",
    "secret_access_key = minioadmin\n",
    "endpoint = http://172.18.255.1:9000\n",
    "```\n",
    " Download iris model\n",
    " \n",
    " ```\n",
    " cd /tmp\n",
    " gsutil cp -r gs://seldon-models/mlserver/iris .\n",
    " ```\n",
    "  \n",
    " Copy iris model to minio\n",
    " \n",
    " ```\n",
    " rclone --config ./rclone.conf copy iris s3://models/iris\n",
    " ```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "completed-style",
   "metadata": {},
   "source": [
    "## Inline RClone Config Example\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "living-identification",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl --format text -d '\\\n",
    "         model { \\\n",
    "            meta: { name:\"iris\"},\\\n",
    "            modelSpec: {uri:\"s3://models/iris\",\\\n",
    "                        storageConfig: { \\\n",
    "                        storageRcloneConfig: \"{\\\"type\\\":\\\"s3\\\",\\\"name\\\":\\\"s3\\\",\\\"parameters\\\":{\\\"provider\\\":\\\"minio\\\",\\\"env_auth\\\":\\\"false\\\",\\\"access_key_id\\\":\\\"minioadmin\\\",\\\"secret_access_key\\\":\\\"minioadmin\\\",\\\"endpoint\\\":\\\"http://minio.minio-system:9000\\\"}}\" \\\n",
    "     } \\\n",
    "                        requirements:[\"sklearn\"],\\\n",
    "                        memoryBytes:500},\\\n",
    "            deploymentSpec:{replicas:1}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/LoadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dying-communist",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/ModelStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "clean-cinema",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"name\":\"mlserver\"}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/ServerStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "perceived-earth",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "!curl -v http://${MESH_IP}/v2/models/iris/infer -H \"Content-Type: application/json\" -H \"seldon-model: iris\"\\\n",
    "        -d '{\"inputs\": [{\"name\": \"predict\", \"shape\": [1, 4], \"datatype\": \"FP32\", \"data\": [[1, 2, 3, 4]]}]}'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eastern-appendix",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model_name\":\"iris\",\"inputs\":[{\"name\":\"input\",\"contents\":{\"fp32_contents\":[1,2,3,4]},\"datatype\":\"FP32\",\"shape\":[1,4]}]}' \\\n",
    "        -plaintext \\\n",
    "        -import-path ../../apis \\\n",
    "        -proto ../../apis/mlops/v2_dataplane/v2_dataplane.proto \\\n",
    "        -rpc-header seldon-model:iris \\\n",
    "       ${MESH_IP}:80 inference.GRPCInferenceService/ModelInfer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "starting-cartridge",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/UnloadModel"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "automotive-convenience",
   "metadata": {},
   "source": [
    "## K8S Secret RClone Config Example\n",
    "\n",
    " * Update endpoint for minio below"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "outstanding-schedule",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%writefile minio-secret.yaml\n",
    "apiVersion: v1\n",
    "kind: Secret\n",
    "metadata:\n",
    "  name: minio-secret\n",
    "  namespace: seldon-mesh\n",
    "type: Opaque\n",
    "stringData:\n",
    "  s3: |\n",
    "    type: s3\n",
    "    name: s3\n",
    "    parameters:\n",
    "      provider: minio\n",
    "      env_auth: false\n",
    "      access_key_id: minioadmin\n",
    "      secret_access_key: minioadmin\n",
    "      endpoint: http://minio.minio-system:9000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "nuclear-journalist",
   "metadata": {},
   "outputs": [],
   "source": [
    "!kubectl apply -f minio-secret.yaml"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "valuable-invalid",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl --format text -d '\\\n",
    "         model { \\\n",
    "            meta: { name:\"iris\"\\\n",
    "                    kubernetesMeta: {namespace: \"seldon-mesh\"}},\\\n",
    "            modelSpec: {uri:\"s3://models/iris\",\\\n",
    "                        storageConfig: { \\\n",
    "                          storageSecretName: \"minio-secret\" \\\n",
    "                         } \\\n",
    "                        requirements:[\"sklearn\"],\\\n",
    "                        memoryBytes:500},\\\n",
    "            deploymentSpec:{replicas:1}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/LoadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "tested-lawyer",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"name\":\"mlserver\"}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/ServerStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "relative-yugoslavia",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "!curl -v http://${MESH_IP}/v2/models/iris/infer -H \"Content-Type: application/json\" -H \"seldon-model: iris\"\\\n",
    "        -d '{\"inputs\": [{\"name\": \"predict\", \"shape\": [1, 4], \"datatype\": \"FP32\", \"data\": [[1, 2, 3, 4]]}]}'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "greatest-short",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model_name\":\"iris\",\"inputs\":[{\"name\":\"input\",\"contents\":{\"fp32_contents\":[1,2,3,4]},\"datatype\":\"FP32\",\"shape\":[1,4]}]}' \\\n",
    "        -plaintext \\\n",
    "        -import-path ../../apis \\\n",
    "        -proto ../../apis/mlops/v2_dataplane/v2_dataplane.proto \\\n",
    "        -rpc-header seldon-model:iris \\\n",
    "       ${MESH_IP}:80 inference.GRPCInferenceService/ModelInfer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "julian-insulin",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/UnloadModel"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "normal-baker",
   "metadata": {},
   "source": [
    "## Using Agent ConfigMap\n",
    "\n",
    " * Edit the AgentConfig map to include the `minio-secret` as one of the rclone defaults, e.g.:\n",
    " \n",
    " ```\n",
    " apiVersion: v1\n",
    "kind: ConfigMap\n",
    "metadata:\n",
    "  name: seldon-agent\n",
    "data:\n",
    "  agent.json: |-\n",
    "    {\n",
    "       \"rclone\" : {\n",
    "           \"config_secrets\": [\"seldon-rclone-gs-public\",\"minio-secret\"]\n",
    "       },\n",
    "    }\n",
    "\n",
    " ```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "greenhouse-mills",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%writefile minio-secret.yaml\n",
    "apiVersion: v1\n",
    "kind: Secret\n",
    "metadata:\n",
    "  name: minio-secret\n",
    "  namespace: seldon-mesh\n",
    "type: Opaque\n",
    "stringData:\n",
    "  s3: |\n",
    "    type: s3\n",
    "    name: s3\n",
    "    parameters:\n",
    "      provider: minio\n",
    "      env_auth: false\n",
    "      access_key_id: minioadmin\n",
    "      secret_access_key: minioadmin\n",
    "      endpoint: http://minio.minio-system:9000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "filled-better",
   "metadata": {},
   "outputs": [],
   "source": [
    "!kubectl apply -f minio-secret.yaml"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "mechanical-editing",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl --format text -d '\\\n",
    "         model { \\\n",
    "            meta: { name:\"iris\"\\\n",
    "                    kubernetesMeta: {namespace: \"seldon-mesh\"}},\\\n",
    "            modelSpec: {uri:\"s3://models/iris\",\\\n",
    "                        requirements:[\"sklearn\"],\\\n",
    "                        memoryBytes:500},\\\n",
    "            deploymentSpec:{replicas:1}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto   ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/LoadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "specified-monster",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/ModelStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cloudy-rebate",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"name\":\"mlserver\"}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/ServerStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "handmade-shaft",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "!curl -v http://${MESH_IP}/v2/models/iris/infer -H \"Content-Type: application/json\" -H \"seldon-model: iris\"\\\n",
    "        -d '{\"inputs\": [{\"name\": \"predict\", \"shape\": [1, 4], \"datatype\": \"FP32\", \"data\": [[1, 2, 3, 4]]}]}'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "organizational-purple",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model_name\":\"iris\",\"inputs\":[{\"name\":\"input\",\"contents\":{\"fp32_contents\":[1,2,3,4]},\"datatype\":\"FP32\",\"shape\":[1,4]}]}' \\\n",
    "        -plaintext \\\n",
    "        -import-path ../../apis \\\n",
    "        -proto ../../apis/mlops/v2_dataplane/v2_dataplane.proto \\\n",
    "        -rpc-header seldon-model:iris \\\n",
    "       ${MESH_IP}:80 inference.GRPCInferenceService/ModelInfer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "mounted-zoning",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/UnloadModel"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "swedish-flooring",
   "metadata": {},
   "source": [
    "# Versions Test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "black-petroleum",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{ \\\n",
    "              \"meta\":{\"name\":\"iris\"},\\\n",
    "              \"modelSpec\":{\"uri\":\"gs://seldon-models/mlserver/iris\",\\\n",
    "                           \"requirements\":[\"sklearn\"],\\\n",
    "                           \"memoryBytes\":50000},\\\n",
    "              \"deploymentSpec\":{\"replicas\":1}}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/LoadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "august-hunger",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"}}' \\\n",
    "         -plaintext \\\n",
    "         -proto ../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/ModelStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "public-agenda",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "!curl -v http://${MESH_IP}/v2/models/iris/infer -H \"Content-Type: application/json\" -H \"seldon-model: iris\"\\\n",
    "        -d '{\"inputs\": [{\"name\": \"predict\", \"shape\": [1, 4], \"datatype\": \"FP32\", \"data\": [[1, 2, 3, 4]]}]}'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "funky-coast",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model_name\":\"iris\",\"inputs\":[{\"name\":\"input\",\"contents\":{\"fp32_contents\":[1,2,3,4]},\"datatype\":\"FP32\",\"shape\":[1,4]}]}' \\\n",
    "        -plaintext \\\n",
    "        -import-path ../../apis \\\n",
    "        -proto ../../apis/mlops/v2_dataplane/v2_dataplane.proto \\\n",
    "        -rpc-header seldon-model:iris \\\n",
    "       ${MESH_IP}:80 inference.GRPCInferenceService/ModelInfer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "delayed-beaver",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"name\":\"mlserver\"}' \\\n",
    "         -plaintext \\\n",
    "         -proto ../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/ServerStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "manual-friendship",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{ \\\n",
    "              \"meta\":{\"name\":\"iris\"},\\\n",
    "              \"modelSpec\":{\"uri\":\"gs://seldon-models/mlserver/iris\",\\\n",
    "                           \"requirements\":[\"sklearn\"],\\\n",
    "                           \"memoryBytes\":20000},\\\n",
    "              \"deploymentSpec\":{\"replicas\":1}}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/LoadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "mineral-frederick",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"},\"allVersions\":true}' \\\n",
    "         -plaintext \\\n",
    "         -proto ../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/ModelStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "grand-dimension",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "!curl -v http://${MESH_IP}/v2/models/iris/infer -H \"Content-Type: application/json\" -H \"seldon-model: iris\"\\\n",
    "        -d '{\"inputs\": [{\"name\": \"predict\", \"shape\": [1, 4], \"datatype\": \"FP32\", \"data\": [[1, 2, 3, 4]]}]}'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "broad-frequency",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model_name\":\"iris\",\"inputs\":[{\"name\":\"input\",\"contents\":{\"fp32_contents\":[1,2,3,4]},\"datatype\":\"FP32\",\"shape\":[1,4]}]}' \\\n",
    "        -plaintext \\\n",
    "        -import-path ../../apis \\\n",
    "        -proto ../../apis/mlops/v2_dataplane/v2_dataplane.proto \\\n",
    "        -rpc-header seldon-model:iris \\\n",
    "       ${MESH_IP}:80 inference.GRPCInferenceService/ModelInfer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "changed-organization",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"name\":\"mlserver\"}' \\\n",
    "         -plaintext \\\n",
    "         -proto ../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/ServerStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "excited-profile",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"}}' \\\n",
    "         -plaintext \\\n",
    "         -proto ../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/UnloadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "olympic-ethnic",
   "metadata": {},
   "outputs": [],
   "source": [
    "!curl -v http://${MESH_IP}/v2/models/iris/infer -H \"Content-Type: application/json\" -H \"seldon-model: iris\"\\\n",
    "        -d '{\"inputs\": [{\"name\": \"predict\", \"shape\": [1, 4], \"datatype\": \"FP32\", \"data\": [[1, 2, 3, 4]]}]}'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bizarre-miller",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"},\"allVersions\":true}' \\\n",
    "         -plaintext \\\n",
    "         -proto ../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/ModelStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "imperial-pathology",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"name\":\"mlserver\"}' \\\n",
    "         -plaintext \\\n",
    "         -proto ../apis/mlops/scheduler/scheduler.proto  ${SCHEDULER_IP}:9004 seldon.mlops.scheduler.Scheduler/ServerStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "waiting-accordance",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
